import os
import shutil

inputdir = r'D:\aconda\envs\labelme\Lib\site-packages\labelme\cli\mask'
outputdir = r'C:\Users\26954\Desktop\VOCdevkit_3\VOC2007\SegmentationClass'

for dir in os.listdir(inputdir):
    oldname = inputdir + os.sep + dir + os.sep + 'label.png'  # os.sep添加系统分隔符
    print("oldname=",oldname)
    png_id = dir
    print("dir=",oldname)
    newname = outputdir + os.sep + png_id + '.png'

    shutil.copyfile(oldname, newname)  # 用os模块中的rename方法对文件改名
    print(oldname, '======>', newname)

